<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!-- 标签库 -->
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>教师信息列表1</title>
    <link rel="stylesheet" type="text/css" href="css/main.css">
    <link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
    <style type="text/css">
        body {
            padding: 20px;
        }

    </style>
</head>
<body>
<div class="app-title">
    <div>
        <h2 style="text-align: center;">教师信息列表</h2>
    </div>
    <ul class="app-breadcrumb breadcrumb side">
        <li class="breadcrumb-item"><i class="fa fa-home fa-lg"></i></li>
        <li class="breadcrumb-item active"><a href="tomain">教师信息</a></li>
    </ul>
</div>
<div class="row">
    <div class="col-md-12">
        <form action="./search" method="get">
            姓名：<input class="" id="name" name="name" type="text">
            科目：<input class="" id="subject" name="subject" type="text">
            <button class="btn btn-success btn-sm" type="sumbit">查询</button>
            <button class="btn btn-info btn-sm" type="button" onclick="javasrcipt:window.location.href='toinsert'">新增
            </button>
        </form>
    </div>

    <div class="col-md-12">
        <div class="tile">
            <div class="tile-body">
                <table class="table table-hover table-bordered" id="sampleTable">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>教师姓名</th>
                        <th>性别</th>
                        <th>手机号</th>
                        <th>年龄</th>
                        <th>所教班级</th>
                        <th>所教科目</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <!-- el表达式  ${后台传过来的值}-->
                    <!-- varStatus  var的下标序号 -->
                    <c:forEach items="${list}" var="tea" varStatus="s">
                        <tr>
                            <td>${tea.id}</td>
                            <td>${tea.name}</td>
                            <td>${tea.sex}</td>
                            <td>${tea.phone}</td>
                            <td>${tea.time}</td>
                            <td>${tea.classcode}</td>
                            <td>${tea.subject}</td>
                            <td>
                                <button class="btn btn-success" type="button"
                                        onclick="javasrcipt:window.location.href='toupdate?id='+${tea.id}">修改
                                </button>
                                <button class="btn btn-danger" type="button" onclick="del(${tea.id})">删除</button>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>


<script src="js/jquery-3.6.0.min.js"></script>
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/main.js"></script>
<script type="text/javascript">
    function del(id) {
        //提示判断弹窗
        if (confirm("确实要删除吗?")) {
            $.ajax({
                type: "post",//方法类型
                url: "delete",//url
                data: {id: id},
                success: function (data) {
                    alert("删除成功！")
                    //刷新当前页面
                    location.reload();
                },
                error: function () {
                    alert("异常请求！");
                }
            });
        } else {
            return;
        }
    }

</script>
</body>
</html>